<?php
/*
 * @Author: 哲学家乔布斯 <wuyangii@qq.com>
 * @Date: 2022-10-25 20:19:21
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 20:22:43
 * @Descripttion: 
 */


namespace app\common\model;

use think\Model;

class AgentEwmLog extends Base
{
    protected $insert = ['addtime','image'];
    protected $update = ['image'];

    //---------------自动完成----------------------
    protected function setAddtimeAttr()
    {
        return time();
    }


     /**
     * @description: 分类名称
     * @param {*} $value
     * @param {*} $data
     * @return {*}
     */    
    public function getCateTitleAttr($value,$data){
        return (new \app\common\model\Classify())->where(['id' => $data['cate_id']])->value('name');
    }
    public function getBrandTitleAttr($value,$data){
        return (new \app\common\model\GoodsBrand())->where(['id' => $data['brand_id']])->value('title');
    }
    public function getCarTitleAttr($value,$data){
        return (new \app\common\model\GoodsCar())->where(['id' => $data['car_id']])->value('title');
    }
    
 


    public function getMoneyAttr($value,$data){
        return (new \app\common\model\AgentGoodsSku())->where(['is_default' => 1])->value('money');
    }
    public function getSkuAttr($value,$data){
        return (new \app\common\model\AgentGoodsSku())->field(['id','sku_title','money'])->where(['goods_id' => $data['id']])->select();
    }
    public function getAgentGoodsTitleAttr($value,$data){
        return (new \app\common\model\AgentGoods())->where(['id' => $data['agent_goods_id']])->value('title');
    }
    public function getAgentGoodsSkuTitleAttr($value,$data){
        return (new \app\common\model\AgentGoodsSku())->where(['id' => $data['agent_goods_sku_id']])->value('sku_title');
    }
    public function getBusUserNameAttr($value,$data){
        return (new \app\common\model\Bus())->where(['id' => $data['bus_id']])->value('user_name');
    }
    public function getAgentUserNameAttr($value,$data){
        return (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->value('usename');
    }
    public function getAgentTitleAttr($value,$data){
        return (new \app\common\model\Agent())->where(['id' => $data['agent_id']])->value('title');
    }
    // public function getStockAttr($value,$data){
    //     return (new \app\common\model\AgentGoodsSku())->where(['goods_id' => $data['id']])->sum('stock');
    // }

    public function getAddtimeTextAttr($value, $data){
        return date('Y-m-d H:i:s', $data['addtime']);
    }
}
